package com.leetcode;

public class MergeSortedArray
{
	public static void main(String[] args)
	{
		MergeSortedArray msa = new MergeSortedArray();
		int[] A = new int[10];
		A[0] = 1;
		A[1] = 3;
		A[2] = 5;
		A[3] = 7;
		int[] B = { 2, 4,6};
		msa.merge(A, 4, B, 3);
		for (int i : A)
		{
			System.out.println(i + "---");
		}
	}

	public void merge(int A[], int m, int B[], int n)
	{
		int k = m + n - 1;
		m--;
		n--;
		while (m >= 0 && n >= 0)
		{
			if (A[m] > B[n])
				A[k--] = A[m--];
			else
				A[k--] = B[n--];
		}
		while (n >= 0)
			A[k--] = B[n--];
	}
}
